#include "Options.h"
#include "neuralNet.h"
#include "FastNN.h"

#include <math.h>
#include <iostream>
#include <stdint.h>
#include <stdlib.h>
#include <fstream>
#include <string>

using namespace std;

int main(int argc, char *argv[])
{

	NeuralNet nn (1, 5, 5, 1);
	ifstream infile;
	infile.open("TubeLookupMod.txt");
	string line;
	vector<double> inputV;
	vector<double> outputV;
	
	int p = 0;
	while(true)
	{
		for(int j = 0; j < 1000; j++)
			getline(infile, line);
		
		if(infile.fail())
			break;
		
		char* temp = new char[line.size()];
		const char* lineStr = line.c_str();
		memcpy(temp, lineStr+1, sizeof(char) * line.size()-1);
		
		char* pch = strtok(temp, " \t");
		
		inputV.push_back(atof(pch));
		pch = strtok(NULL, " \t");
		outputV.push_back(atof(pch));
		delete[] temp;
		
	}
	infile.close();
	
	double** input = new double*[inputV.size()];
	for(int i = 0; i < inputV.size(); i++)
	{
		input[i] = new double[1];
		input[i][0] = inputV[i];
	}
	
	double** output = new double*[outputV.size()];
	for(int i = 0; i < outputV.size(); i++)
	{
		output[i] = new double[1];
		output[i][0] = outputV[i];
	}
		
	int turns = 1000001;
	
	nn.trainNetwork(input, output, inputV.size(), turns);
	
	
	ofstream outfile;
	outfile.open("output.txt");
	double* inputP = new double;
	for(int i = 0; i < inputV.size(); i++)
	{
		*inputP = input[i][0];
		double* results = nn.predict(inputP);
		outfile << input[i][0] << "\t" << results[0] << "\t" << output[i][0] << endl;
		delete results;
	}
	
	return 0;
}